# Use this file to easily define all of your cron jobs.
#
# It's helpful, but not entirely necessary to understand cron before proceeding.
# http://en.wikipedia.org/wiki/Cron

# Example:
#
# set :output, "/path/to/my/cron_log.log"
#
# every 2.hours do
#   command "/usr/bin/some_great_command"
#   runner "MyModel.some_method"
#   rake "some:great:rake:task"
# end
#
# every 4.days do
#   runner "AnotherModel.prune_old_records"
# end

# Learn more: http://github.com/javan/whenever

# so when CRON is running a task it knows where is your rails exec file
# env :GEM_HOME, ENV['GEM_HOME']
#
# # Default environment
# set :environment, ENV.fetch("RAILS_ENV") { 'development' }
#
# # My cusotom job runner
job_type :rake, "cd :path && :environment_variable=:environment bundle exec rake :task --silent :output"

env :PATH, ENV['PATH']
env :BUNDLE_PATH, ENV['BUNDLE_PATH']
env :RAILS_MASTER_KEY, ENV['RAILS_MASTER_KEY']
env :SECRET_KEY_BASE_DUMMY, 1
env :REDIS_URL, "redis://10.0.18.118:6379/0"

set :environment, ENV["RAILS_ENV"]

log_path = ::File.expand_path('../../log/cron_log.log', __FILE__)
FileUtils.touch log_path unless File.exist? log_path
set :output, log_path
every :weekday, at: ['8:16am'] do
  rake "init:stock"
end
every :weekday, at: ['8:18am'] do
  rake "init:block"
end
every :weekday, at: %w['6:08pm', '8:08pm'] do
  rake "init:limit_list"
end
every :weekday, at: %w[15:58]  do
  rake "init:buy_point"
end

every :weekday, at: ['16:16'] do
  rake "choice:auto_add_choice"
end

every :weekday, at: ['9:31am', '9:35am', '9:40am', '14:55']  do
  rake "realtime:block"
end

# 交易日每隔15分钟
every '*/15 9,10,11,13,14,15 * * 1-5' do
  rake "realtime:block"
end

# 交易日每5分钟
every '*/5 9,10,11,13,14 * * 1-5' do
  rake "realtime:index"
  rake "realtime:buy_point_volume_score"
end

# 交易日每分钟
every '15-59 9 * * 1-5' do
  rake "realtime:sina_today_all"
  rake "realtime:limit_ths_flow"
  rake "realtime:buy_point_flow"
end
every '0-30 11 * * 1-5' do
  rake "realtime:sina_today_all"
  rake "realtime:limit_ths_flow"
  rake "realtime:buy_point_flow"
end
every '* 10,13,14 * * 1-5' do
  rake "realtime:sina_today_all"
  rake "realtime:limit_ths_flow"
  rake "realtime:buy_point_flow"
end

every 1.minute do
  rake "ths:fluctuation"
end

# :weekend, :weekday monday tuesday wednesday thursday friday saturday sunday
# :hour, :day, :month, :year
# every 3.hours do # 1.minute 1.day 1.week 1.month 1.year
# every 1.day, at: ['4:30 am', '6:00 pm'] do   am 上午  pm 下午
# every '0 0 27-31 * *' do